package com.javathread.th5;

public class TestMap {

	public static void main(String[] args) {
		int initialCapacity = 16 ;
		float loadFactor = 0.75f;
		int concurrencyLevel = 16;
		 if (!(loadFactor > 0) || initialCapacity<0 || concurrencyLevel<=0) 
			 throw new IllegalArgumentException(); //非法参数异常
		 if (concurrencyLevel > 65536) // 并发度
			 concurrencyLevel = 65536; //最大并发度65536  最大支持65536个工人同时干活
		 int sshift = 0;
		 int ssize = 1;
		 while (ssize < concurrencyLevel) {
			 ++ sshift;
			 ssize <<= 1;//位运算  左移1位
		 }
		 
		 int segmentShift = 32 -sshift;
		 int segmentMask = ssize - 1;
		 if (initialCapacity > 1073741824) //最大容量
			 initialCapacity = 1073741824;
		 int c = initialCapacity / ssize;
		 if (c * ssize < initialCapacity) 
			 ++c;
		 int cap = 2;
		 while (cap < c) 
			 cap <<= 1;
			 System.out.println(cap * loadFactor);
			 System.out.println("the cap is : " + cap);
		
		 int hash = hash(123456);
		 System.out.println("hash is " + Integer.toBinaryString(hash));
	}
	
	private static int hash(Object k) {
		int h = 13;
		h ^= k.hashCode();
		
		h += (h << 15) ^ 0xffffcd7d;
		h ^= (h >>> 10);
		h += (h <<  3);
		h ^= (h >>> 6);
		h += (h <<  2) + (h << 14);
		return h ^ (h >>> 16);
	}

}
